package com.atguigu.gulimall.thirdpart;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@EnableDiscoveryClient
@SpringBootApplication
public class GulimallThirdPartApplication {

    public static void main(String[] args) {
        SpringApplication.run(GulimallThirdPartApplication.class, args);
    }

    @Autowired
    OSS ossClient;

    @Test
    public void testUpload() throws FileNotFoundException {
        // Endpoint以杭州为例，其它Region请按实际情况填写。
        String endpoint = "oss-cn-beijing.aliyuncs.com";
        // 云账号AccessKey有所有API访问权限，建议遵循阿里云安全最佳实践，创建并使用RAM子账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建。
        String accessKeyId = "LTAI4GHedtaDAYuFhn7rLDxV";
        String accessKeySecret = "80BhnJXLmxdCppnzdudLhMHTMhARo0";

        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        //上传文件流。
        InputStream inputStream = new FileInputStream("C:\\Users\\admin\\Desktop\\电气控制\\20201010101452.png");
        ossClient.putObject("wk9527", "1111.jpg", inputStream);

        // 关闭OSSClient。
        ossClient.shutdown();
        System.out.println("上传成功.");
    }

}
